package com.migu.hbase

import com.migu.utils.ConfigUtil
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.hbase.HBaseConfiguration
import org.apache.hadoop.hbase.client.{Connection, ConnectionFactory}

/**
  * Created by maguoyun on 2017/03/21.
  */
object HbUtil {
  def getConn(): Connection = {
    ConnectionFactory.createConnection(getHBConf())
  }

  def getHBConf(): Configuration = {
    val quorum = ConfigUtil.getConfig().getOrElse("spark.hbase.quorum", "192.168.107.88")
    val clientPort = ConfigUtil.getConfig().getOrElse("spark.hbase.clientPort", "2181")
    val master = ConfigUtil.getConfig().getOrElse("spark.hbase.master", "192.168.107.88:60000")
    val conf = HBaseConfiguration.create()
    conf.set("hbase.zookeeper.quorum", quorum)
    conf.set("hbase.zookeeper.property.clientPort", clientPort)
    conf.set("hbase.master", master)
    conf.set("zookeeper.znode.parent", "/hbase")
    conf
  }
}
